<h1><?php echo $title_for_layout = __d('lil_ads', 'Add/Edit Ad', true); ?></h1>
<?php $this->set(compact('title_for_layout')); ?>
<div class="form">
	<?php 
		echo $this->Form->create('AdsBanner', array('type' => 'file'));
	?>
	<fieldset>
		<?php
			echo $this->Form->input('id');
			if (!$this->Html->value('ads_campaign_id')) {
				echo $this->Form->input('ads_campaign_id', array(
					'type'    => 'select',
					'label'   => __d('lil_ads', 'Campaign', true) . ':',
					'options' => $campaigns
				));
			} else {
				echo $this->Form->input('ads_campaign_id', array('type' => 'hidden'));
			}
			echo $this->Form->input('referer', array('type'=>'hidden'));
			echo $this->Form->input('title', array(
				'label' => __d('lil_ads', 'Title (alt)', true) . ':',
				'error' => __d('lil_ads', 'Title is required.', true)
			));
			echo $this->Form->input('link', array(
				'label' => __d('lil_ads', 'Link', true) . ':',
				'error' => __d('lil_ads', 'Link must be in a proper form or empty.', true)
			));
			
			echo $this->Form->input('width', array(
				'label' => __d('lil_ads', 'Width', true) . ':',
				'error' => __d('lil_ads', 'Width has to be numeric.', true)
			));
			echo $this->Form->input('height', array(
				'label' => __d('lil_ads', 'Height', true) . ':',
				'error' => __d('lil_ads', 'Height has to be numeric.', true)
			));
			echo $this->Form->input('kind', array(
				'type'    => 'radio',
				'options' => array(
					'I' => __d('lil_ads', 'Image', true),
					'F' => __d('lil_ads', 'Flash', true),
					'P' => __d('lil_ads', 'Plain Text', true),
					'H' => __d('lil_ads', 'Html', true)
				),
				'legend'  => __d('lil_ads', 'Type', true).':'));
		?>
	</fieldset>
	<fieldset id="Kind1">
		<?php
			echo $this->Form->input('filename', array('type'=>'file', 'label'=>__d('lil_ads', 'File', true).':'));
			echo '<div class="input">'.$this->Html->value('filename').'</div>';
		?>
	</fieldset>
	<fieldset id="Kind2">
		<?php
			echo $this->Form->input('body', array('label'=>__d('lil_ads', 'Text/HTML', true).':'));
		?>
	</fieldset>
	<?php
		echo $this->Form->submit(__d('lil_ads', 'OK', true));
		echo $this->Form->end();
	?>
</div>

<?php echo $this->Html->script('/lil_ads/js/jquery-1.4.2.min'); ?>
<script type="text/javascript">
	$(document).ready(function(){
		$("input[name$='data[Banner][kind]']").each(function(){
			$(this).click(function(){
				var rbv = $("input[name='data[Banner][kind]']:checked").val();
				if(rbv == "I" || rbv == "F") {
					$("#Kind1").show();
					$("#Kind2").hide();
				} else {
					$("#Kind2").show();
					$("#Kind1").hide();
				}
			});
		});
		$("input[name='data[Banner][kind]']:checked").click();
	});
</script>